﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using StudentManage.Data;

namespace StudentManage.Web.Admin.Management.NewsManage
{
    public partial class NewsList : SecurityPage
    {
        public override string PrivCode()
        {
            return "7d90cc332df86c37";
        }

        int i = 0;
        public string GetXN()
        {
            if(i==0)
                i = (this.AspNetPager1.PageSize) * (this.AspNetPager1.CurrentPageIndex - 1);

            i += 1;
            return i.ToString();
        }

        public string GetXYName(string XYDM)
        {
            if (XYDM == "" || XYDM == "0") return "公共信息";
            xydm md = xydm.Where("XYDM=@0", XYDM).FirstOrDefault();
            return md == null ? "" : md.XYMC;
        }

        private void RepBanding()
        {
            int RowCount = Data.News.All().Count();
            this.AspNetPager1.RecordCount = RowCount;
            int PageSize = this.AspNetPager1.PageSize;
            int SkipCount = PageSize*(this.AspNetPager1.CurrentPageIndex-1);
            
            List<Data.News> list = Data.News.All().OrderByDescending(p => p.AddTime).Skip(SkipCount).Take(PageSize).ToList();
            this.Rep_DataList.DataSource = list;
            this.Rep_DataList.DataBind();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            RepBanding();
        }

        protected void Rep_DataList_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            if (e.CommandName == "Del")
            {
                int NewId = Convert.ToInt32(e.CommandArgument);
                Data.News.Delete("id=@0", NewId);
                RepBanding();
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            this.RepBanding();
        }
    }
}